#include "header.h"

void *autoShutdown(void *ptr)
{
	printf("AUTOSHUTDOWN THREAD CREATED with time = %dsec\n",node.getAutoShutdown());


	int autoShutdownTime = node.getAutoShutdown();
	
	for(int i=0; i <1000; i++)
	{
		usleep(autoShutdownTime*1000);
		//if(shutdownFlag == true && joinToTheNetworkFlag == false)
		if(shutdownFlag == true)
		{
			printf("Autoshutdown Thread EXIT due to Shutdown\n");
			fileObject.printIndexDetails();
			pthread_exit(NULL);
		}
	}
	shutdownFlag = true;
	fileObject.printIndexDetails();
	printf("Autoshutdown Thread EXIT due to TIME OUT\n");
	pthread_exit(NULL);

	return NULL;
}
